import {createRouter, createWebHistory} from 'vue-router'
import {useEmployeeStore} from '@/stores'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/login',
            component: () => import('@/views/login/loginPage.vue')
        },
        {
            path: '/',
            component: () => import('@/views/layout/layoutContainer.vue'),
            redirect: '/employee/employeeManager',
            children: [
                {
                    path: '/employee/employeeManager',
                    component: () => import('@/views/employee/employeeManager.vue'),
                    name: '员工管理'
                },
                {
                    path: '/category/categoryManager',
                    component: () => import('@/views/category/categoryManager.vue'),
                    name: '分类管理'
                },
                {
                    path: '/food/foodManager',
                    component: () => import('@/views/food/foodManager.vue'),
                    name: '食物管理'
                },
                {
                    path: '/foodRecipe/foodRecipeManager',
                    component: () => import('@/views/foodRecipe/foodRecipeManager.vue'),
                    name: '食谱管理'
                },
                {
                    path: '/foodRecipeDetails/foodRecipeDetailsManager',
                    component: () =>
                        import('@/views/foodRecipeDetails/foodRecipeDetailsManager.vue'),
                    name: '食谱明细'
                },
                {
                    path: '/log/generalLog',
                    component: () => import('@/views/log/generalLog.vue'),
                    name:'通用日志'
                },
                {
                    path: '/log/loginLog',
                    component: () => import('@/views/log/loginLog.vue'),
                    name:'登录日志'
                }
            ]
        }
    ]
})
router.beforeEach((to) => {
    const employeeStore = useEmployeeStore()
    if (employeeStore.logoutStatus && to.path !== '/login') return '/login'
})
export default router
